package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.io.IOException;
import java.time.Duration;

public class HomePage extends Utils {
    public static String url = "http://8.155.1.153:8081/home";
    public HomePage() {
        super(url);
    }

    public void checkLeft() throws IOException {
        // 检查左侧菜单栏是否成功加载和显示
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul"));
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(2) > span > a > div > span.anticon.ant-pro-base-menu-item-icon > span > svg"));
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(3) > span > a > div > span.anticon.ant-pro-base-menu-item-icon > span > svg"));
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(4) > div > span > div > span.anticon.ant-pro-base-menu-item-icon > span > svg > path"));
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(5) > span > a > div > span.anticon.ant-pro-base-menu-item-icon > span > svg > path"));
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(6) > div > span > div > span.anticon.ant-pro-base-menu-item-icon > span > svg"));

    }
    public void checkMiddle() throws IOException {
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
        // 检查中栏是否成功加载和显示
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div"));
        //头像
        WebElement image=driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div/main/div/div[1]/div[2]/div/div/div/div/div/div[1]/span/img"));
        assert image.isDisplayed() : "图片未显示";
        //问卷  考试
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div/main/div/div[1]/div[2]/div/div/div/div/div/div[3]/div[1]/div/div[1]"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div/main/div/div[1]/div[2]/div/div/div/div/div/div[3]/div[2]/div/div[1]"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div/main/div/div[1]/div[2]/div/div/div/div/div/div[2]/div[1]"));
        driver.findElement(By.cssSelector("#rc-tabs-0-tab-exam")).click();
        driver.findElement(By.cssSelector("#rc-tabs-0-panel-exam > div > div > div > div.ant-table-wrapper > div > div > div > div > div > table > thead > tr > th:nth-child(1)"));
        driver.findElement(By.cssSelector("#rc-tabs-0-tab-survey")).click();
        driver.findElement(By.cssSelector("#rc-tabs-0-panel-survey > div > div > div > div.ant-table-wrapper > div > div > div > div > div > table > thead > tr > th:nth-child(1)"));
        driver.findElement(By.cssSelector("#rc-tabs-0-tab-surveyHistory")).click();
        driver.findElement(By.cssSelector("#rc-tabs-0-panel-surveyHistory > div > div > div > div.ant-table-wrapper > div > div > div > div > div > table > thead > tr > th:nth-child(2)"));
        driver.findElement(By.cssSelector("#rc-tabs-0-tab-examHistory")).click();
        driver.findElement(By.cssSelector("#rc-tabs-0-panel-examHistory > div > div > div > div.ant-table-wrapper > div > div > div > div > div > table > thead > tr > th:nth-child(2)"));


    }

    public void checkRight() throws IOException {
        // 检查右侧菜单栏是否成功加载和显示
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div"));
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/a[1]")).click();
        driver.findElement(By.cssSelector("#root > div > div.survey-main-navigator > div.actions-container > div:nth-child(2)"));
        driver.navigate().back();
        driver.findElement(By.xpath("//*[@id=\"sk-layout\"]/div/div/section/div/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/a[2]")).click();
        driver.findElement(By.cssSelector("#editorContent > div > div > div.header > div.header-content > div.evaluation-total-score > div.total-scpre-title"));
        driver.navigate().back();
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }
}
